<template>
	<view class="content">
		<view class="head">
			<view class="head_image">
				<!-- <image :src="image_url?image_url:'../../static/image/logo.png'" style="border-radius: 10rpx"></image> -->
				<!-- #ifdef MP-WEIXIN -->
				<button v-if="isLogin" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
					<image style="width: 100rpx;height: 100rpx;border-radius: 50%" :src="image_url"></image>
				</button>
				<image v-else style="width: 100rpx;height: 100rpx;border-radius: 50%" :src="image_url"
					@tap="binduser()"></image>

				<!-- #endif -->
				<!-- #ifndef MP-WEIXIN -->
				<image :src="image_url" style="width: 100rpx;height: 100rpx;border-radius: 100rpx;" @tap="binduser()">
				</image>
				<!-- #endif -->
			</view>
			<view class="head_name" @tap="binduser()">
				<view class="name">{{ mobile ? mobile : '游客' }}</view>
			</view>
			<image v-if="mobile" @click="goNav('/pages/my/set/set')" src="../../static/image/my/set.png"
				style="width: 40rpx;height: 40rpx;margin-top: 80rpx;margin-right: 20rpx;" mode=""></image>
		</view>
		<!-- 列表 -->
		<view class="margin padding-lr-sm padding-tb bg-white radius">
			<view class="flex justify-between align-center">
				<view class="text-lg text-bold text-black">我的订单</view>
				<view class="flex text-gray" @click="goSwt(0)">
					<text>立即查看</text>
					<u-icon name="arrow-right" width='11rpx' height='18rpx'></u-icon>
				</view>
			</view>
			<view class="flex justify-around margin-top">
				<view class="text-center" @click="goSwt(1)" style="position: relative;">
					<image src="../../static/image/my/1.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">待付款</view>
					<view class="weinumber" v-if="order1">{{order1}}</view>
				</view>
				<view class="text-center" @click="goSwt(2)" style="position: relative;">
					<image src="../../static/image/my/2.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">待接单</view>
					<view class="weinumber" v-if="order2">{{order2}}</view>
				</view>
				<view class="text-center" @click="goSwt(4)" style="position: relative;">
					<image src="../../static/image/my/3.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">派送中</view>
					<view class="weinumber" v-if="order3">{{order3}}</view>
				</view>
				<view class="text-center" @click="goSwt(5)">
					<image src="../../static/image/my/4.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">已完成</view>
				</view>
			</view>
		</view>

		<view class="margin padding-lr-sm padding-tb bg-white radius">
			<view class="flex justify-between align-center">
				<view class="text-lg text-bold text-black">推荐工具</view>
			</view>
			<view class="flex flex-wrap">
				<!-- <view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pageA/attract/attract')">
					<image src="../../static/image/my/5.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">成为代理商</view>   
				</view> -->
				<view class="text-center margin-tb-sm" style="width: 25%;"
					@click="divideScale!=null && divideScale!=0?goNav('/pageA/extension/team'):goNav('/pageA/extension/extension')">
					<image src="../../static/image/my/13.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">推广中心</view>
				</view>
				<view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pageA/wallet/wallet')"
					v-if="xcxSelect=='是'">
					<image src="../../static/image/my/14.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">我的钱包</view>
				</view>
				<view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pages/my/hongbao/hongbao')"
					v-if="xcxSelect=='是'">
					<image src="../../static/image/my/5.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">我的红包</view>
				</view>
				<view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pages/my/invitationUser')">
					<image src="../../static/image/my/12.png" style="width: 55rpx;height:45rpx;" mode=""></image>
					<view class="text-sm margin-top-xs">分享好友</view>
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<view class="text-center margin-tb-sm" style="width: 25%;" @click="goRider()">
					<image src="../../static/image/my/6.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">接单赚钱</view>
				</view>
				<!-- #endif -->

				<view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pageA/feedback/feedback')"
					v-if="xcxSelect=='是'">
					<image src="../../static/image/my/4.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">意见反馈</view>
				</view>

				<view class="text-center margin-tb-sm" style="width: 25%;"
					@click="goNav('/pageA/userXieyi/trainingList')">
					<image src="../../static/image/my/22.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">用户指南</view>
				</view>

				<view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pageA/kefu/kefu')">
					<image src="../../static/image/my/8.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">联系客服</view>
				</view>
				<view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pageA/address/address')">
					<image src="../../static/image/my/9.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">地址管理</view>
				</view>
				<!-- <view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pageA/test/test')">
					<image src="../../static/image/my/9.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">测试</view>
				</view> -->
				<!-- <view class="text-center margin-tb-sm" style="width: 25%;" @click="goNav('/pages/my/set/set')">
					<image src="../../static/image/my/set.png" style="width: 55rpx;height: 55rpx;" mode=""></image>
					<view class="text-sm">系统设置</view>
				</view> -->

			</view>
		</view>

		<view class="margin" v-if="divideScale==0" @click="goNav(bgurl)">
			<image :src="bgImg" mode="scaleToFill" style="width:100%;height:246upx;"></image>
		</view>
	</view>
</template>

<script>
	import configdata from '../../common/config.js';
	export default {
		data() {
			return {
				divideScale: '',
				image_url: '../../static/image/logo.png',
				mobile: '',
				checkCertification: -1,
				arr: [],
				showModal: true,
				xcxSelect: '是',

				tuiguang: '',
				tuiguangImg: '',
				appID: '',
				bgImg: '',
				bgurl: '',
				order1: '',
				order2: '',
				order3: '',
				timer: '',
				isLogin: false,
			}
		},
		onLoad() {
			this.xcxSelect = uni.getStorageSync('xcxSelect')
			this.$Request.getT('/app/common/type/248').then(res => { //跑腿师傅端微信小程序APPID 248
				if (res.code === 0) {
					this.appID = res.data.value;
				}
			});
			this.$Request.getT('/app/common/type/310').then(res => { // 我的页面活动图片 310
				if (res.code === 0) {
					this.bgImg = res.data.value;
				}
			});
			this.$Request.getT('/app/common/type/311').then(res => { // 我的页面活动跳转地址 311
				if (res.code === 0) {
					this.bgurl = res.data.value;
				}
			});

			let token = this.$queue.getData("token");
			if (token) {
				this.getZiZhi()

				this.timer = setInterval(() => {
					this.getorder1()
					this.getorder2()
					this.getorder3()
				}, 3000);
			}


		},
		onHide() {
			clearInterval(this.timer)
		},
		onShow() {

			let token = this.$queue.getData("token");
			if (token) {
				this.isLogin = true
				this.getUserInfo();
				this.getorder1()
				this.getorder2()
				this.getorder3()
			} else {
				this.image_url = '../../static/image/logo.png';
				this.mobile = '';
				this.order1 = ''
				this.order2 = ''
				this.order3 = ''
				this.isLogin = false
			}
		},
		onShareAppMessage(res) { //发送给朋友
			return {
				title: this.tuiguang,
				path: '/pages/index/index',
				imageUrl: this.tuiguangImg,
			}
		},
		onShareTimeline(res) { //分享到朋友圈
			return {
				title: this.tuiguang,
				path: '/pages/index/index',
				imageUrl: this.tuiguangImg,
			}
		},
		methods: {
			//微信填写能力获取头像
			onChooseAvatar(e) {
				console.log(e.detail.avatarUrl)
				let that = this;
				let token = uni.getStorageSync('token');
				uni.showLoading({
					title: '上传中...'
				});
				uni.uploadFile({
					url: that.config('APIHOST1') + '/alioss/upload', //仅为示例，非真实的接口地址
					// url: 'https://pt2.0.xianmxkj.com/sqx_fast/alioss/upload', //仅为示例，非真实的接口地址
					filePath: e.detail.avatarUrl,
					// filePath: res.tempFilePaths[0],
					header: {
						token: token
					},
					name: 'file',
					success: uploadFileRes => {
						let url = JSON.parse(uploadFileRes.data).data;
						that.$Request.postJson('/app/user/updateUserImageUrl?avatar=' + url).then(
							res => {
								uni.hideLoading();
								if (res.code === 0) {
									that.$queue.showToast("更新成功");
									that.getUserInfo();
								}
							});
					}
				});

			},
			getorder1() {
				let data = {
					page: 1,
					limit: 1,
					indentState: 0
				}
				this.$Request.getT('/app/indent/findUserIndent', data).then(res => {
					if (res.code === 0) {
						this.order1 = res.data.totalCount
					}
					uni.hideLoading()
				});
			},
			getorder2() {
				let data = {
					page: 1,
					limit: 1,
					indentState: 2
				}
				this.$Request.getT('/app/indent/findUserIndent', data).then(res => {
					if (res.code === 0) {
						this.order2 = res.data.totalCount
					}
					uni.hideLoading()
				});
			},
			getorder3() {
				let data = {
					page: 1,
					limit: 1,
					indentState: 4
				}
				this.$Request.getT('/app/indent/findUserIndent', data).then(res => {
					if (res.code === 0) {
						this.order3 = res.data.totalCount
					}
					uni.hideLoading()
				});
			},
			// 分享文案和图片
			getZiZhi() {
				this.$Request.getT('/app/common/type/276').then(res => {
					if (res.code === 0) {
						this.tuiguang = res.data.value;
					}
				});
				this.$Request.getT('/app/common/type/277').then(res => {
					if (res.code === 0) {
						this.tuiguangImg = res.data.value;
					}
				});
			},
			goSwt(e) {
				uni.setStorageSync('current', e)
				setTimeout(function() {
					uni.switchTab({
						url: '/pages/order/order',
					})
				}, 10)
			},
			goRider() {
				let token = this.$queue.getData("token");
				if (token) {
					let that = this
					uni.navigateToMiniProgram({
						appId: that.appID,
						path: '/pages/index/index',
						extraData: {
							'data1': 'test'
						},
						success(res) {
							// 打开成功
							console.log("打开成功")
						}
					})
				} else {
					this.bindlogin();
				}
			},
			goNav(url) {

				let token = this.$queue.getData("token");
				if (token) {
					uni.navigateTo({
						url: url
					})
				} else {
					this.bindlogin();
				}
			},
			getUserInfo() {
				this.$Request.getT('/app/userinfo/findUserInfoById').then(res => {
					console.log(res)
					if (res.code == 0) {
						if (parseInt(res.data.checkCertification)) {
							this.checkCertification = parseInt(res.data.checkCertification)
						} else {
							this.checkCertification = -1;
						}

						this.$queue.setData("userId", res.data.userId);
						this.$queue.setData("invitationCode", res.data.invitationCode ? res.data.invitationCode :
							'0');
						this.$queue.setData("status", res.data.status);
						this.$queue.setData("nickName", res.data.nickName ? res.data.nickName : res
							.data.userName);
						this.image_url = res.data.avatar ? res.data.avatar : '../../static/image/logo.png';
						this.$queue.setData("image_url", this.image_url);
						this.mobile = res.data.nickName ? res.data.nickName : res.data.userName
						this.divideScale = res.data.divideScale
					}
				});
			},
			bindlogin() {
				let token = this.$queue.getData("token");
				if (!token) {
					uni.navigateTo({
						url: './register'
					})
				}
			},
			bindapprove() {
				let token = this.$queue.getData("token");
				if (token) {
					uni.navigateTo({
						url: '/pages/my/approve/approve'
					})
				} else {
					this.bindlogin();
				}
			},
			binduser() {
				let token = this.$queue.getData('token');
				if (!token) {
					this.bindlogin();
					return;
				}
				uni.navigateTo({
					url: '/pages/my/userphone/userphone'
				});
				// if (index == 1) {
				// 	let that = this;
				// 	var url = null;
				// 	let userId = this.$queue.getData('userId');
				// 	uni.showActionSheet({
				// 		// itemList按钮的文字接受的是数组
				// 		itemList: ["查看头像", "从相册选择图片"],
				// 		success(e) {
				// 			var index = e.tapIndex
				// 			if (index === 0) {
				// 				// 用户点击了预览当前图片
				// 				// 可以自己实现当前头像链接的读取
				// 				let url = that.image_url;
				// 				let arr = []
				// 				arr.push(url)
				// 				uni.previewImage({
				// 					// 预览功能图片也必须是数组的
				// 					urls: arr
				// 				})
				// 			} else if (index === 1) {
				// 				uni.chooseImage({
				// 					count: 1, //默认9
				// 					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				// 					sourceType: ['album'], //从相册选择
				// 					success: function(res) {
				// 						uni.showLoading({
				// 							title: '上传中...'
				// 						});
				// 						let token = uni.getStorageSync('token');
				// 						uni.uploadFile({
				// 							url: that.config("APIHOST1") +
				// 								'/alioss/upload', //仅为示例，非真实的接口地址
				// 							filePath: res.tempFilePaths[0],
				// 							header: {
				// 								token: token
				// 							},
				// 							name: 'file',
				// 							success: uploadFileRes => {
				// 								url = JSON.parse(uploadFileRes.data).data;
				// 								let datafrom = {
				// 									avatar: url
				// 								}

				// 								// console.log(JSON.parse(uploadFileRes.data).data)
				// 								that.$Request.postJson(
				// 										'/app/user/updateUser', datafrom)
				// 									.then(
				// 										res => {
				// 											uni.hideLoading();
				// 											if (res.code === 0) {
				// 												that.$queue.showToast(
				// 													"更新成功");
				// 												that.getUserInfo();
				// 											}
				// 										});
				// 							}
				// 						});
				// 					}
				// 				});
				// 			}
				// 		}
				// 	})
				// }
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			}
		}
	}
</script>

<style>
	button::after {
		border: none;
		background-color: none;
	}

	button {
		position: relative;
		display: block;
		margin-left: auto;
		margin-right: auto;
		padding-left: 0px;
		padding-right: 0px;
		box-sizing: border-box;
		text-decoration: none;
		line-height: 1.35;
		overflow: hidden;
		color: #666666;
		background-color: #fff;
		width: 100%;
		height: 100%;
	}

	body {
		background: #F5F5F5;
	}

	/* #ifndef MP-WEIXIN */
	page {
		background: #F2EDED;
	}

	/* #endif */

	.content {
		width: 100%;
	}

	button::after {
		border: none;
		background-color: none;
	}

	button {
		position: relative;
		display: block;
		margin-left: auto;
		margin-right: auto;
		padding-left: 0px;
		padding-right: 0px;
		box-sizing: border-box;
		text-decoration: none;
		/* line-height: 1.35; */
		overflow: hidden;
		color: #666666;
		/* background-color: #fff; */
		background-color: rgba(255, 255, 255, 0) !important;
		width: 100%;
		height: 100%;
		margin-top: 90rpx;

	}

	.btn {
		font-size: 28upx;
		/* width: 95%; */
		text-align: center;
		background: #FFFFFF;
		margin-top: 6rpx;
	}

	.head {
		/* width: 100%; */
		background: #ffffff;
		height: 200rpx;
		display: flex;
		margin: 30rpx;
		border-radius: 16rpx;
	}

	.head_image {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.head_image image {
		width: 90rpx;
		height: 90rpx;
	}

	.head_name {
		flex: 4;
		position: relative;
	}

	.name {
		position: absolute;
		top: 75rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.approve {
		position: absolute;
		top: 100rpx;
		font-size: 24rpx;
		color: #999999;
	}

	/* 列表 */
	.use_list {
		width: 100%;
		background: #ffffff;
		margin-top: 20rpx;
	}

	.list_box {
		width: 90%;
		margin: 0 auto;
		display: flex;
		height: 110rpx;
	}

	.box_left {
		flex: 1;
		display: flex;
		justify-content: left;
		align-items: center;
	}

	.box_right {
		flex: 1;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		color: #808080;
	}

	.use_name {
		margin-left: 30rpx;
		font-size: 32rpx;
	}

	.use_image image {
		width: 50rpx;
		height: 50rpx;
	}

	.weinumber {
		width: 35upx;
		height: 35upx;
		background: red;
		color: #fff;
		border-radius: 35upx;
		position: absolute;
		top: 0upx;
		right: -10upx;
		z-index: 99;
	}
</style>